<template>
	<div>
		<div>用户名：<input v-model="username"/></div>
		<div>密码：<input type="password" v-model="password"/></div>
		<div><button @click="handleLogin">登录</button></div>
	</div>
</template>

<script>
	export default{
		data(){
			return {
				username:"",
				password:"",
			}
		},
		methods:{
			handleLogin(){
				if(this.username.length < 4 || this.password.length < 4){
					this.$message.warning("请输入用户名或密码")
				}else{
					
					// 保存token到本地存储
					localStorage.setItem('token',"123")
					// 设置token
					this.$store.commit('setToken',"123")
					this.$store.commit('setUsername',"wasdfghjkl")
					// 登录成功提示
					this.$message.success("登录成功")
					// 跳转到首页
					this.$router.push('/admin/home')
					
					
					// const _this = this
					// this.$request.post('login/index', {
					//     username: this.username,
					//     password: this.password
					//   })
					//   .then(function (response) {
					//     console.log('token',response.token);
					// 	// 保存token到本地存储
					// 	localStorage.setItem('token',response.token)
					// 	// 设置token
					// 	_this.$store.commit('setToken',response.token)
					// 	_this.$store.commit('setUsername',response.username)
					// 	// 登录成功提示
					// 	_this.$message.success("登录成功")
					// 	// 跳转到首页
					// 	_this.$router.push('/admin/home')
					//   })
					//   .catch(function (error) {
					//     console.log(error);
					//   });
				}
			},
		}
	}
</script>

<style>
</style>